package cn.wit.tech.controller;

import cn.wit.tech.condition.SearchCurriculumCondition;
import cn.wit.utils.pojo.Curriculum;
import cn.wit.tech.service.CurriculumService;
import cn.wit.utils.response.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/tech/curriculum")
@CrossOrigin
@Api(tags = "课程管理")
public class CurriculumController {
    private Logger logger = LoggerFactory.getLogger(CurriculumController.class);

    @Autowired
    private CurriculumService curriculumService;

    @PostMapping("/insertCurriculum")
    @ApiOperation("课程新增")
    public Result insertCurriculum(@RequestBody Curriculum curriculum) {
            return this.curriculumService.insert(curriculum);
    }

    @PostMapping("/deleteCurriculum")
    @ApiOperation("课程删除")
    public Result deleteCurriculum(int id) {
            return this.curriculumService.deleteById(id);
    }

    @PostMapping("/updateByIdCurriculum")
    @ApiOperation("课程更新")
    public Result updateByIdCurriculum(@RequestBody Curriculum curriculum) {
        return this.curriculumService.updateById(curriculum);
    }

    @GetMapping("/searchCurriculum/{num}/{size}")
    @ApiOperation(value = "条件搜索课程")
    public Result searchCurriculum(@PathVariable("num") int num,
                                   @PathVariable("size") int size,SearchCurriculumCondition condition) {
        IPage<Curriculum> page = new Page<>(num, size);
        return this.curriculumService.searchPage(page, condition);
    }


}

